function chunkArrayInGroups(arr, size) {
    let ans = [];

    for (let i = 0; i <= arr.length - size; i += size) {
        ans.push(arr.slice(i, i + size));
    }
    if (i < arr.length)
        ans.push(arr.slice(i));
    return ans;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);